package com.example.shoppingcart.Controller;

import com.example.model.shppingcart.dto.GoodsAndCountDTO;
import com.example.common.result.UserResult;
import com.example.model.shppingcart.dto.ShoppingCartDTO;
import com.example.shoppingcart.service.ShoppingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/member/cart")
public class ShopingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;
    @PostMapping
    public UserResult addCart(@RequestBody GoodsAndCountDTO goodsAndCountDTO){
        ShoppingCartDTO shoppingCartDTO = shoppingCartService.addCart(goodsAndCountDTO);
        return UserResult.success(shoppingCartDTO);
    }
    @GetMapping
    public UserResult selectCart(){
        List<ShoppingCartDTO> list = shoppingCartService.selectCart();
        return UserResult.success(list);
    }

    @DeleteMapping("/{ids}")
    public UserResult delectCart(@RequestParam List<Integer> ids){
        shoppingCartService.delectCart(ids);
        return UserResult.success();
    }
}
